function openJS() {
	alert('loaded')
}
function closeJS() {
	alert('closed')
}
function addValue(row, value, config) {
	document.getElementById("handlerClass" + row).value = value;
	document.getElementById("closediv").click();
	if (config == 'true') {
		TINY.box
				.show({
					html : 'This handler needs configuration setting. Please click on the \'Settings\' button.',
					animate : true,
					close : false,
					mask : false,
					boxid : 'success',
					autohide : 3,
					top : -14,
					left : -17
				});
	}
}
function getXMLHttp() {
	var xmlHttp;
	try {
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX!")
				return false;
			}
		}
	}
	return xmlHttp;
}
function handleError(xmlHttp) {
	var response = xmlHttp.responseText;
	var n = response.split("_ROW_NUM_");
	try {
		document.getElementById("errorTab" + n[0]).innerHTML = '&nbsp;&nbsp;'
				+ xmlHttp.statusText + ' [' + xmlHttp.status + '][' + n[1]
				+ ']';
	} catch (e) {
		TINY.box.show({
			html : xmlHttp.statusText + ' [' + xmlHttp.status + '] ['
					+ response + ']',
			animate : false,
			close : false,
			boxid : 'error',
			top : 5
		})
	}
}
function enable(i) {
	var xmlHttp = getXMLHttp();
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			handleEnable(xmlHttp);
		}
	}
	var uri = "/simulate/global/admin?enable=true&url="
			+ document.getElementById("urltext" + i).value + "&class="
			+ document.getElementById("handlerClass" + i).value + "&rowid=" + i;
	xmlHttp.open("POST", uri, true);
	xmlHttp.send();
}

function handleEnable(xmlHttp) {
	var status = xmlHttp.status;
	var response = xmlHttp.responseText;
	if (status == 200) {
		var n = response.split("_ROW_NUM_");
		document.getElementById("disablelink" + n[0]).style.display = 'block';
		document.getElementById("enablelink" + n[0]).style.display = 'none';
		document.getElementById("urltext" + n[0]).readOnly = true;
		document.getElementById("errorTab" + n[0]).innerHTML = '&nbsp;';
	} else {
		handleError(xmlHttp);
	}
}

function disable(i) {
	var xmlHttp = getXMLHttp();
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			handleDisable(xmlHttp);
		}
	}
	var uri = "/simulate/global/admin?disable=true&url="
			+ document.getElementById("urltext" + i).value + "&class="
			+ document.getElementById("handlerClass" + i).value + "&rowid=" + i;

	xmlHttp.open("POST", uri, true);
	xmlHttp.send();
}
function handleDisable(xmlHttp) {
	var status = xmlHttp.status;
	var response = xmlHttp.responseText;
	if (status == 200) {
		var n = response.split("_ROW_NUM_");
		document.getElementById("disablelink" + n[0]).style.display = 'none';
		document.getElementById("enablelink" + n[0]).style.display = 'block';
		document.getElementById("urltext" + n[0]).readOnly = false;
		document.getElementById("errorTab" + n[0]).innerHTML = '&nbsp;';
	} else {
		handleError(xmlHttp);
	}
}
function exit() {
	var xmlHttp = getXMLHttp();
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			handleExit(xmlHttp);
		}
	}
	var search = "url=null";
	try {
		search = window.location.search;
	} catch (e) {
	}
	xmlHttp.open("POST", "/simulate/global/exit?url=" + search, true);
	xmlHttp.send();
}
function promptUnload() {
	
}



function handleExit(xmlHttp) {
	try {

		var table = document.getElementById("outer");
		table.deleteRow(0);
		table.deleteRow(0);
		TINY.box
				.show({
					html : 'Application Stopped! Please restart again. <br/><a href=\"javascript:window.close();\"><b color=\"white\">Close</b></a>  this window',
					animate : true,
					close : false,
					boxid : 'error',
					top : 5
				});

	} catch (e) {

	}
}
function addRow(i) {
	try {
		var table = document.getElementById("confs");
		var rowCount = table.rows.length;
		var row = table.insertRow(rowCount);
		var cell1 = row.insertCell(0);
		var regex = new RegExp('_ROW_ID_', 'g');
		var regex2 = new RegExp('_NEXT_PORT_', 'g');
		START_PORT = START_PORT + 1;
		cell1.innerHTML = document.getElementById("oneblock").innerHTML
				.replace(regex, rowCount).replace(regex2, parseInt(START_PORT));
	} catch (e) {
	}
}
function deleteRow(i) {
	disable(i);
	var table = document.getElementById("confs");
	table.deleteRow(i);
}
function saveAll() {
	try {
		var all = document.getElementsByTagName("input");
		var count = 0;
		for ( var i = 0, max = all.length; i < max; i++) {
			if (all[i].id.substring(0, 7) == "urltext") {
				count = count + 1;
			}
		}
		var uri = '/simulate/global/save?';
		for ( var j = 0; j < count; j++) {
			try {
				var dis = document.getElementById("enablelink" + j).style.display;
				uri = uri + 'conf' + j + '='
						+ document.getElementById("urltext" + j).value
						+ '_SEP_'
						+ document.getElementById("handlerClass" + j).value
						+ '_SEP_'
						+ ((dis == '' || dis == 'block') ? 'true' : 'false')
						+ '&';
			} catch (e) {
			}
		}
		var xmlHttp = getXMLHttp();
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4) {
				handleSave(xmlHttp);
			}

		}
		xmlHttp.open("POST", uri, true);
		xmlHttp.send();
	} catch (e) {
	}
}
function handleSave(xmlHttp) {
	var status = xmlHttp.status;
	if (status == 200) {
		var response = xmlHttp.responseText;
		TINY.box
				.show({
					html : 'Data saved...' + response
							+ ' configuration(s) are invalid',
					animate : false,
					close : false,
					mask : false,
					boxid : 'success',
					autohide : 2,
					top : -14,
					left : -17
				});

	} else {
		handleError(xmlHttp);
	}
}
function openLookupPopup(i) {
	var dis = document.getElementById("enablelink" + i).style.display;
	if (dis == '' || dis == 'block') {
		TINY.box.show({
			url : '/simulate/global/hander?rowid=' + i,
			post : 'id=16',
			width : 500,
			height : 200,
			opacity : 20,
			topsplit : 3
		});
	} else {
		TINY.box.show({
			html : 'Cannot be changed in enabled state!',
			animate : false,
			close : false,
			mask : false,
			boxid : 'success',
			autohide : 2,
			top : -14,
			left : -17
		});
	}
}

function showLog() {
	var lines = document.getElementById("loglines").value;
	lines = (lines == '' ? '200' : lines);
	TINY.box.show({
		iframe : '/simulate/global/logview?lines=' + lines,
		boxid : 'frameless',
		width : 750,
		height : 500,
		fixed : false,
		maskopacity : 40
	});
}

function showHelp() {
	TINY.box.show({
		iframe : '/simulate/global/src?src=http/help/help.pdf',
		boxid : 'frameless',
		width : 850,
		height : 600,
		fixed : false,
		maskopacity : 40
	});
}

function openSettings(i) {
	var clazz = document.getElementById("handlerClass" + i).value;
	TINY.box.show({
		iframe : '/simulate/global/hander/conf?handler=' + clazz,
		boxid : 'frameless',
		width : 750,
		height : 600,
		fixed : false,
		maskopacity : 40
	});
}
